package com.jiaozi.system.controller;



import com.baomidou.mybatisplus.core.metadata.IPage;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.jiaozi.core.annotation.Log;
import com.jiaozi.core.table.JzTable;
import com.jiaozi.base.utils.bean.R;
import com.jiaozi.system.pojo.param.sys.role.RolePageParam;
import com.jiaozi.system.pojo.param.sys.role.RoleSaveUpdateParam;
import com.jiaozi.system.pojo.vo.sys.role.RoleInfoVO;
import com.jiaozi.system.pojo.vo.sys.role.RoleListVO;
import com.jiaozi.system.pojo.vo.sys.role.RolePageVO;
import com.jiaozi.system.service.SysRoleService;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 系统-角色(SysRole)表控制层
 *
 * @author jiaozi
 * @since 2024-08-15 14:02:36
 */
@RestController
@RequestMapping("/sysRole")
@Tag(name = "角色管理")
public class SysRoleController {
    /**
     * 服务对象
     */
    @Autowired
    private SysRoleService sysRoleService;

    @Operation(summary = "角色初始化",description = "角色初始化")
    @GetMapping("/info")
    @ApiOperationSupport(order = 1)
    @Log("角色初始化")
    public  R<JzTable> info(){
        JzTable jzTable=new JzTable(RolePageVO.class);
        jzTable.setRefreshBotton(true);
        jzTable.setQueryCriteriaBotton(true);
        jzTable.setColumnsBotton(true);
        jzTable.setPage(true);
        jzTable.setDataUrl("/sysRole/page/");
        return R.ok(jzTable);
    }

    @Operation(summary = "查询角色分页",description = "查询角色分页")
    @GetMapping("/page/{pageNum}/{pageSize}")
    @ApiOperationSupport(order = 1)
    @Log("查询角色分页")
    public R<IPage<RolePageVO>> rolePage(@Parameter(name ="pageNum" ,description = "页码", required = true)
                                                @PathVariable(value = "pageNum") Long pageNum,
                                         @Parameter(name ="pageSize" ,description = "页条数", required = true)
                                                @PathVariable(value = "pageSize") Long pageSize,
                                         RolePageParam param){
        return sysRoleService.rolePage(pageNum,pageSize,param);
    }


    @Operation(summary = "查询角色列表",description = "查询角色列表")
    @GetMapping("/list")
    @ApiOperationSupport(order = 1)
    @Log("查询角色列表")
    public R<List<RoleListVO>> roleList(RolePageParam param){
        return sysRoleService.roleList(param);
    }




    @Operation(summary = "获取角色信息",description = "获取角色信息")
    @GetMapping("/{roleId}")
    @ApiOperationSupport(order = 2)
    public R<RoleInfoVO> roleInfo(@Parameter(name ="roleId" ,description = "角色编号", required = true)
                                  @PathVariable(value = "roleId") String roleId){
        return sysRoleService.roleInfo(roleId);

    }
    
    @Operation(summary = "新增角色信息",description = "新增角色信息")
    @PostMapping("/")
    @ApiOperationSupport(order = 3)
    public R roleSave(@RequestBody RoleSaveUpdateParam roleSaveUpdateParam){
        return sysRoleService.roleSave(roleSaveUpdateParam);
    }


    @Operation(summary = "修改角色信息",description = "修改角色信息")
    @PutMapping("/{roleId}")
    @ApiOperationSupport(order = 4)
    public R roleUpdate(@Parameter(name ="roleId" ,description = "角色编号", required = true)
                        @PathVariable(value = "roleId") String roleId,@RequestBody RoleSaveUpdateParam roleSaveUpdateParam){
        return sysRoleService.roleUpdate(roleId,roleSaveUpdateParam);
    }


    @Operation(summary = "删除角色信息",description = "删除角色信息")
    @DeleteMapping("/{roleId}")
    @ApiOperationSupport(order = 4)
    public R roleDelete(@Parameter(name ="roleId" ,description = "角色编号", required = true)
                        @PathVariable(value = "roleId") String roleId){
        return sysRoleService.roleDelete(roleId);
    }


    @Operation(summary = "变更角色状态",description = "变更角色状态")
    @PutMapping("updateRoleState/{roleId}")
    @ApiOperationSupport(order = 65)
    public R updateRoleState(@Parameter(name ="roleId" ,description = "角色编号", required = true)
                              @PathVariable(value = "roleId") String roleId){
        return sysRoleService.updateRoleState(roleId);
    }
}

